import java.util.Arrays;

public class Leet978 {
    public int maxTurbulenceSize(int[] arr) {
        int[] dp = new int[arr.length];
        Arrays.fill(dp,1);
        for (int i = 1; i < arr.length; i++) {
            if (i%2==0)//小
                if (arr[i]>arr[i-1])
                    dp[i] = dp[i-1]+1;
                else dp[i] = 1;
            else
                if (arr[i]<arr[i-1])
                    dp[i]= dp[i-1]+1;
                else dp[i] = 1;
        }
        Arrays.sort(dp);
        return dp[arr.length-1];
    }
}
